package cn.tansanqinger.dao.sql.group;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.tansanqinger.dao.sql.IChatMessageSqlDao;
import cn.tansanqinger.pojo.Chatmessage;

@Repository
public class ChatMessageSqlDaoImpl {

	@Autowired
	private IChatMessageSqlDao dao;
	
	/**
	 * 往前查询15条数据
	 * @param account
	 * @param time
	 * @return
	 */
	public List<Chatmessage> selectChatMessageLe(String account, long time) {
		QueryWrapper<Chatmessage> queryWrapper = new QueryWrapper<Chatmessage>();
		queryWrapper.lambda().eq(Chatmessage::getSaccount, account).le(Chatmessage::getCtime, time);
		Page<Chatmessage> page = new Page<Chatmessage>(1, 15);
		IPage<Chatmessage> iPage = dao.selectPage(page, queryWrapper);
		return iPage.getRecords();
	}
	
	/**
	 * 往后查询15条聊天记录
	 * @param account
	 * @param time
	 * @return
	 */
	public List<Chatmessage> selectChatMessageGt(String account, long time){
		QueryWrapper<Chatmessage> queryWrapper = new QueryWrapper<Chatmessage>();
		queryWrapper.lambda().eq(Chatmessage::getSaccount, account).gt(Chatmessage::getCtime, time);
		Page<Chatmessage> page = new Page<Chatmessage>(1, 15);
		IPage<Chatmessage> iPage = dao.selectPage(page, queryWrapper);
		return iPage.getRecords();
	}
	
	/**
	 * 查询全部数据
	 * @param account
	 * @return
	 */
	public List<Chatmessage> selectChatMessageAll(String account){
		QueryWrapper<Chatmessage> queryWrapper = new QueryWrapper<Chatmessage>();
		queryWrapper.lambda().eq(Chatmessage::getSaccount, account);
		return dao.selectList(queryWrapper);
	}
}
